package org.itsolutions.javaBackup.spi.common.io;

import java.io.File;

/**
 * 
 * @author Tomas Fecko
 */
public interface IByteBuffers {
	
	//////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////// INSERT OPERATIONS ////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////
	/**
	 * 
	 * @param pFile file to read
	 * @return this
	 */
	IByteBuffers bufferFile(File pFile);

	/**
	 * 
	 * @param pArray array to buffer
	 * @return this
	 */
	IByteBuffers bufferArray(byte[] pArray);
//	
//	/**
//	 * 
//	 * @param pString string
//	 * @return byteBuffers
//	 */
//	IByteBuffers putString(String pString);
	
	//////////////////////////////////////////////////////////////////////////////////////////////
	///////////////////////////////////// RETRIEVE OPERATIONS ////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////

	/**
	 * 
	 * @return get the content of all the buffers in one array
	 */
	byte[] getArray();

	/**
	 * Method returns next specified number of bytes in array.
	 * @param pReturnArraySize return array size
	 * @return next count of bytes in array, or null, if remaining() <  pReturnArraySize
	 */
	byte[] getArray(int pReturnArraySize);
	
	/**
	 * Return boolean, or throws BufferUnderflowException if remaining < 1.
	 * @return boolean
	 */
	boolean getBoolean();
	
	/**
	 * Return boolean, or throws BufferUnderflowException if remaining < 1.
	 * @return boolean
	 */
	byte getByte();
	
	/**
	 * Return short, or throws BufferUnderflowException if remaining < 2.
	 * @return short
	 * 
	 */
	int getShort();
	
	/**
	 * Return int, or throws BufferUnderflowException if remaining < 4.
	 * @return int
	 * 
	 */
	int getInt();

	/**
	 * Return float, or throws BufferUnderflowException if remaining < 4.
	 * @return float
	 */
	float getFloat();

	/**
	 * Return long, or throws BufferUnderflowException if remaining < 8.
	 * @return long
	 */
	long getLong();

	/**
	 * Return double, or throws BufferUnderflowException if remaining < 8.
	 * @return double
	 */
	double getDouble();
	
	//////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////// OTHER  ///////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////

	/**
	 * Method release all used byteBuffers back to pool.
	 * @return number of released byteBuffers
	 */
	int releaseByteBuffers();
	
	/**
	 * Number of buffers from pool in this byteBuffers stack.
	 * @return number of buffers used
	 */
	int getNumberOfBuffers();
	
	/**
	 * 
	 * @return number of byte buffers that are available in pool
	 */
	int getAvailablePooledBuffers();

	/**
	 * 
	 * @return number of buffers, that are missing (are in use) from buffer pool
	 */
	int getUsedBuffersCount();
	
	/**
	 * 
	 * @return remaining
	 */
	int remaining();
	
	/**
	 * 
	 * @return position in byte buffers
	 */
	int position();
	
	/**
	 * Moves pointer forward from the current position by specified number of bytes.
	 * @param pNumberOfBytes number of bytes to move forward
	 * @return this
	 */
	IByteBuffers moveForward(int pNumberOfBytes);
}






